package com.gxa.saas.portal.controller.btopfore;



import com.gxa.saas.core.utils.JwtUtil;
import com.gxa.saas.portal.entity.vo.wylvo.HomeDataVo;
import com.gxa.saas.portal.entity.vo.wylvo.OrderListVo;
import com.gxa.saas.portal.service.WGoodsService;
import com.gxa.saas.portal.service.WHomeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/whome")
public class Home {

    @Resource
    private WHomeService wHomeService;

    @Resource
    private WGoodsService wGoodsService;

    @ApiOperation("首页数据显示")
    @GetMapping("/selectHomeData")
    @Transactional
    public Map selectHomeData(HttpServletRequest request){
//月份订单返回最近7个月的数据
        HomeDataVo homeDataVo = new HomeDataVo();


        //根据登录账号获取商铺id
        String sid= JwtUtil.getUsername(request.getAttribute("token1").toString());
        Integer shopId = wGoodsService.selectShopId(sid);

        List<OrderListVo> orderList = wHomeService.selectOrderList(shopId);
        Integer monthOrder = wHomeService.selectMonthOrder(shopId);
        Integer weekOrder = wHomeService.selectWeekOrder(shopId);
        Integer countOrder = wHomeService.selectCountOrder(shopId);
        Integer psOrder = wHomeService.selectPSOrder(shopId);
        homeDataVo.setOrderList(orderList);
        homeDataVo.setMonthOrder(monthOrder);
        homeDataVo.setCountOrder(countOrder);
        homeDataVo.setPsOrder(psOrder);
        homeDataVo.setWeekOrder(weekOrder);
        homeDataVo.setRghtsOrder(0);

        List<HomeDataVo> list = new ArrayList<>();

        if(list.size()==0){
            List<HomeDataVo> list1 = new ArrayList<>();
            List<OrderListVo> list2 = new ArrayList<>();
            OrderListVo orderListVo=    new OrderListVo();
            list2.add(orderListVo);
            homeDataVo.setOrderList(list2);
            list1.add(homeDataVo);
            Map map = new HashMap();
            map.put("msg","查询成功,暂无数据");
            map.put("code",200);
            map.put("data",list1);
            return map;
        }

        list.add(homeDataVo);

        Map map = new HashMap();
        map.put("msg","查询成功");
        map.put("code",200);
        map.put("data",list);
        return map;
    }
}
